full <- readRDS("jarpfull_plus.RDS")

library(stargazer)

# Internment Status -------------------------------------------------------
# Table 3
table(cut(full$interned_len_yrs, c(0, .99, 1.99, 2.99, 3.99, 4.99, 5)))

interest_01_lfe<- lm(interest_all_mc ~ self.interned + fam.only + precamp_all + age + gender + generation, full)
govhelp_01_lfe <- lm(govhelp_all ~ self.interned + fam.only + precamp_all + age + gender + generation, full)
poladv_01_lfe <- lm(pol_adv_all ~ self.interned + fam.only + precamp_all + age + gender + generation, full)
leader_01_lfe <- lm(leader ~ self.interned + fam.only + precamp_all + age + gender + generation, full)

# Table 6 (Appendix)
stargazer(interest_01_lfe, govhelp_01_lfe, poladv_01_lfe, leader_01_lfe, 
          keep = c("self.interned", "fam.only"),
          model.names = TRUE, no.space = TRUE,
          dep.var.labels = rep(c("Political Interest", "Distrust", "Political Advice", "Leadership Approach"), 1),
          keep.stat = c("n", "rsq"), 
          covariate.labels = c("Internment Status (Self)", "Internment Status (Family)"), 
          initial.zero = FALSE,  add.lines = list(c("Generation Fixed Effects", 
                                                    "\\checkmark", "\\checkmark", "\\checkmark"),
                                                  c("Pre-Internment Location Fixed Effects", 
                                                    "\\checkmark", "\\checkmark", "\\checkmark")),
          title = "Internment Status and Political Engagement")

# Figure 4 (Main Text)
map_df(list(interest_01_lfe, govhelp_01_lfe, poladv_01_lfe, leader_01_lfe), broom::tidy, 
       .id = "model") %>% filter(term == "self.interned" | term == "fam.only") %>%  mutate(outcome = recode(model, `1` = "Political Interest", `2` = "Political Distrust", `3` = "Political Advice", `4` = "Leadership Approach")) %>% mutate(Group = as.factor(recode(term, `self.interned` = "Direct Exposure", `fam.only` = "Family-Only Exposure"))) %>% mutate(Group = fct_relevel(Group, c("Family-Only Exposure", "Direct Exposure"))) %>% ggplot(aes(x = outcome, y = estimate, color = Group)) + geom_hline(yintercept = 0, alpha = .5) + geom_pointrange(aes(ymin = estimate - 1.96*std.error, ymax = estimate + 1.96*std.error), size = .5, position = position_dodge(.5)) + geom_errorbar(aes(ymin = estimate - 1.405*std.error, ymax = estimate + 1.405*std.error), size = 1, width = 0, position = position_dodge(.5)) + theme_minimal() + scale_color_grey(start = .6, end = .1) + labs(x = "Outcome", y = "Coefficient Estimate", title = "Internment Status and Political Engagement") + coord_flip() +  guides(color = guide_legend(reverse = TRUE))

# Table 7 (Appendix)
map_df(list(interest_01_lfe, govhelp_01_lfe, poladv_01_lfe, leader_01_lfe), broom::tidy, 
       .id = "model") %>% filter(term == "self.interned" | term == "fam.only") -> coefs

map_df(list(car::linearHypothesis(interest_01_lfe, "self.interned = fam.only", singular.ok = TRUE),
            car::linearHypothesis(govhelp_01_lfe, "self.interned = fam.only", singular.ok = TRUE),
            car::linearHypothesis(poladv_01_lfe, "self.interned = fam.only", singular.ok = TRUE),
            car::linearHypothesis(leader_01_lfe, "self.interned = fam.only", singular.ok = TRUE)), 
       broom::tidy, .id = "model") 

# Internment Length -------------------------------------------------------
interest_len_mc_si <- lm(interest_all_mc ~ interned_len_yrs + age + gender + generation, full, subset = self.interned == 1)
govhelp_len_si <- lm(govhelp_all ~ interned_len_yrs + age + gender + generation, full, subset = self.interned == 1)
poladv_len_si <- lm(pol_adv_all ~ interned_len_yrs + age + gender + generation, full, subset = self.interned == 1)
leader_len_si <- lm(leader ~ interned_len_yrs + age + gender + generation, full, subset = self.interned == 1)

# Table 8 (Appendix)
stargazer(interest_len_mc_si, govhelp_len_si, poladv_len_si, leader_len_si,
          keep = "interned_len_yrs",
          model.names = TRUE, no.space = TRUE,
          dep.var.labels = rep(c("Political Interest", "Distrust", 
                                 "Political Advice", "Leadership Approach"), 1),
          keep.stat = c("n", "rsq"), covariate.labels = "Internment Length", 
          initial.zero = FALSE,  add.lines = list(c("Generation Fixed Effects", 
                                                    "Y", "Y", "Y", "Y")),
          title = "Internment Length and Political Engagement")

# Figure 5 (Main Text)
map_df(list(interest_len_mc_si, govhelp_len_si, poladv_len_si, leader_len_si), broom::tidy, 
       .id = "model") %>% filter(term == "interned_len_yrs") %>% mutate(outcome = recode(model, `1` = "Political Interest", `2` = "Political Distrust", `3` = "Political Advice", `4` = "Leadership Approach")) %>% mutate(group = recode(term, `interned_len_yrs` = "Internment Length (Years)")) %>% ggplot(aes(x = outcome, y = estimate, group = outcome)) + geom_pointrange(aes(ymin = estimate - 1.96*std.error, ymax = estimate + 1.96*std.error), size = .5) + labs(x = "Outcome", y = "Coefficient Estimate", title = "Internment Length and Political Engagement") + geom_hline(yintercept = 0, alpha = .25) + theme_minimal() + theme(plot.title = element_text(hjust = 0.5)) + scale_y_continuous(breaks = round(seq(-.15, .15, by = 0.025),2)) + coord_flip() 

# Table 9 (Appendix)
subgroup_interest <- lm(interest_all_mc ~ interned_len_yrs + age.subgroup + gender + age, full, subset = self.interned == 1)
subgroup_govhelp <- lm(govhelp_all ~ interned_len_yrs + gender + age.subgroup + age + gender + generation, full, subset = self.interned == 1)
subgroup_poladv <- lm(pol_adv_all ~ interned_len_yrs + age + age.subgroup + gender + generation, full, subset = self.interned == 1)
subgroup_leader <- lm(leader ~ interned_len_yrs + age +  age.subgroup + gender + generation, full, subset = self.interned == 1)

stargazer(subgroup_interest, subgroup_govhelp, subgroup_poladv, subgroup_leader,
          keep.stat = c("n", "rsq"),
          keep = c("interned_len_yrs", "age.subgroup"),
          dep.var.labels = rep(c("Political Interest", "Distrust", 
                                 "Political Advice", "Leadership Approach"), 3),
          covariate.labels = c("Internment Length",
                               "Age-Based Subgroup",
                               "Final Year = 1945",
                               "Internment Length x Age-Based Subgroup",
                               "Internment Length x Final Year = 1945"),
          add.lines = list(c("Generation Fixed Effects", 
                             "\\checkmark", "\\checkmark", "\\checkmark"),
                           c("Controls", 
                             "Age, Gender", "Age, Gender", "Age, Gender")),
          title = "Internment Length: Subgroup Analyses",
          model.names = TRUE, no.space = TRUE,
          initial.zero = FALSE,
          star.cutoffs = c(.05, .01, .001))

# Table 10 (Appendix)
yr1945_interest <- lm(interest_all_mc ~ interned_len_yrs + age + gender + generation, full, subset = 
                        self.interned == 1 & yr.1945 == 1)
yr1945_govhelp <- lm(govhelp_all ~ interned_len_yrs + age + gender + generation, full, subset = 
                       self.interned == 1 & yr.1945 == 1)
yr1945_poladv <- lm(pol_adv_all ~ interned_len_yrs + age + gender + generation, full, subset = 
                      self.interned == 1 & yr.1945 == 1)
yr1945_leader <- lm(leader ~ interned_len_yrs + age + gender + generation, full, subset = 
                      self.interned == 1 & yr.1945 == 1)

stargazer(yr1945_interest, yr1945_govhelp, yr1945_poladv, yr1945_leader,
          keep.stat = c("n", "rsq"),
          keep = c("interned_len_yrs", "age.subgroup"),
          dep.var.labels = rep(c("Political Interest", "Distrust", 
                                 "Political Advice", "Leadership Approach"), 3),
          covariate.labels = c("Internment Length",
                               "Age-Based Subgroup",
                               "Final Year = 1945",
                               "Internment Length x Age-Based Subgroup",
                               "Internment Length x Final Year = 1945"),
          add.lines = list(c("Generation Fixed Effects", 
                             "\\checkmark", "\\checkmark", "\\checkmark"),
                           c("Controls", 
                             "Age, Gender", "Age, Gender", "Age, Gender")),
          title = "Internment Length: Subgroup Analyses",
          model.names = TRUE, no.space = TRUE,
          initial.zero = FALSE,
          star.cutoffs = c(.05, .01, .001))

# Table 17 (Appendix)
mil.balance <- lm(military.svc ~ self.interned + fam.only + generation + age + gender + precamp_all, full)
income.balance <- lm(income.num ~ self.interned + fam.only + generation + age + gender + precamp_all, full)

stargazer(mil.balance, income.balance,
          keep.stat = c("n", "rsq"),
          model.names = TRUE, no.space = TRUE,
          initial.zero = FALSE,
          keep = c("self.interned", "fam.only"),
          covariate.labels = c("Direct Exposure to Internment",
                               "Family-Only Exposure to Internment"))

# Table 18 (Appendix)
interest_01_lfe_ageb <- lm(interest_all_mc ~ self.interned*age.b + 
                             fam.only*age.b + 
                             precamp_all + gender + generation, full)

govhelp_01_lfe_ageb <- lm(govhelp_all ~ self.interned*age.b + 
                            fam.only*age.b + precamp_all + age + gender + generation, full)

poladv_01_lfe_ageb <- lm(pol_adv_all ~ self.interned*age.b + 
                           fam.only*age.b +
                           precamp_all + age + gender + generation, full)

leader_01_lfe_ageb <- lm(leader ~ self.interned*age.b + 
                           fam.only*age.b + 
                           precamp_all + age + gender + generation, full)

stargazer(interest_01_lfe_ageb, govhelp_01_lfe_ageb, poladv_01_lfe_ageb, leader_01_lfe_ageb,
          keep = c("self.interned:age",
                   "self.interned:age.b"),
          model.names = TRUE, no.space = TRUE,
          dep.var.labels = 
            rep(c("Political Interest", "Distrust", "Political Advice", "Leadership Approach"), 2),
          keep.stat = c("n", "rsq"), 
          initial.zero = FALSE,  add.lines = list(c("Generation Fixed Effects", 
                                                    rep("\\checkmark", 6)),
                                                  c("Pre-Internment Location Fixed Effects", 
                                                    rep("\\checkmark", 6))),
          title = "Internment Status and Political Engagement (Conditional Effects by Age)")


# Table 19 (Appendix)
interest_len_ageb <- lm(interest_all_mc ~ interned_len_yrs*age.b + gender + age + generation, full, subset = self.interned == 1)
govhelp_len_ageb <- lm(govhelp_all ~ interned_len_yrs*age.b + gender + age + gender + generation, full, subset = self.interned == 1)
poladv_len_ageb <- lm(pol_adv_all ~ interned_len_yrs*age.b + age + gender + generation, full, subset = self.interned == 1)
leader_len_ageb <- lm(leader ~ interned_len_yrs*age.b + age + gender + generation, full, subset = self.interned == 1)

stargazer(interest_len_ageb, govhelp_len_ageb, poladv_len_ageb, leader_len_ageb,
          keep = c("interned_len_yrs:age.b"),
          model.names = TRUE, no.space = TRUE,
          dep.var.labels = 
            rep(c("Political Interest", "Distrust", "Political Advice", "Leadership Approach"), 2),
          keep.stat = c("n", "rsq"), 
          covariate.labels = c("Age x Internment Length", "Interned Adult x Internment Length"), 
          initial.zero = FALSE,  add.lines = list(c("Generation Fixed Effects", 
                                                    rep("\\checkmark", 6)),
                                                  c("Pre-Internment Location Fixed Effects", 
                                                    rep("\\checkmark", 6))),
          title = "Internment Length and Political Engagement (Conditional Effects by Age)")

# Figure 17 (Appendix)
full$generation <- as.factor(full$generation)

p1 <- interflex::inter.binning(full, "interest_all_mc", "self.interned", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Direct Exposure", Ylabel = "Political Advice", 
                               cex.lab = 0, cex.main = 1,
                               main = "Political Interest") 

p2 <- interflex::inter.binning(full, "govhelp_all", "self.interned", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Direct Exposure", Ylabel = "Political Distrust", cex.lab = 0,
                               main = "Political Distrust")

p3 <- interflex::inter.binning(full, "pol_adv_all", "self.interned", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Direct Exposure", Ylabel = "Political Advice", cex.lab = 0,
                               main = "Political Advice")

p4 <- interflex::inter.binning(full, "leader", "self.interned", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Direct Exposure", Ylabel = "Leadership Style", cex.lab = 0,
                               main = "Leadership Style")

p1b <- interflex::inter.binning(full, "interest_all_mc", "fam.only", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Direct Exposure", Ylabel = "Political Advice", 
                                cex.lab = 0,
                                main = "Political Interest")

p2b <- interflex::inter.binning(full, "govhelp_all", "fam.only", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Family Exposure", Ylabel = "Political Distrust", cex.lab = 0,
                                main = "Political Distrust")

p3b <- interflex::inter.binning(full, "pol_adv_all", "fam.only", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Family Exposure", Ylabel = "Political Advice", cex.lab = 0,
                                main = "Political Advice")

p4b <- interflex::inter.binning(full, "leader", "fam.only", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Family Exposure", Ylabel = "Leadership Style", cex.lab = 0,
                                main = "Leadership Style")

g <- grid.arrange(p1$graph, p2$graph, p3$graph, p4$graph)
ggsave("self_interned_x_age.pdf", g)
grid.arrange(p1b$graph, p2b$graph, p3b$graph, p4b$graph)

# Figure 18 (Appendix)
p1c <- interflex::inter.binning(subset(full,
                                       self.interned == 1),
                                "interest_all_mc", "interned_len_yrs", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Family Exposure", Ylabel = "Political Interest", cex.lab = 0,
                                main = "Political Interest")

p2c <- interflex::inter.binning(subset(full,
                                       self.interned == 1), "govhelp_all", "interned_len_yrs", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Family Exposure", Ylabel = "Political Distrust", cex.lab = 0,
                                main = "Political Distrust")

p3c <- interflex::inter.binning(subset(full,
                                       self.interned == 1), "pol_adv_all", "interned_len_yrs", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Family Exposure", Ylabel = "Political Advice", cex.lab = 0,
                                main = "Political Advice")

p4c <- interflex::inter.binning(subset(full,
                                       self.interned == 1), "leader", "interned_len_yrs", "age", na.rm = T, FE = "precamp_all", Z = c("generation", "gender"), Dlabel = "Family Exposure", Ylabel = "Leadership Style", cex.lab = 0, 
                                main = "Leadership Style")

g2 <- grid.arrange(p1c$graph, p2c$graph, p3c$graph, p4c$graph)
ggsave("interned_len_x_age.pdf", g2)

# Table 20 (Appendix)
assim.status <- lm(continuum ~ self.interned + fam.only + precamp_all + age + gender, full)
assim.length <- lm(continuum ~ interned_len_yrs + age + gender, full, subset = self.interned == 1)

stargazer(assim.status,assim.length, 
          keep = c("self.interned", "fam.only", "interned_len_yrs"),
          model.names = TRUE, no.space = TRUE,
          dep.var.labels = rep(c("Political Interest", "Distrust", "Political Advice", "Leadership Approach"), 1),
          keep.stat = c("n", "rsq"), 
          covariate.labels = c("Internment Status (Self)", "Internment Status (Family)", "Internment Length"), 
          initial.zero = FALSE,  add.lines = list(c("Generation Fixed Effects", 
                                                    "\\checkmark", "\\checkmark", "\\checkmark"),
                                                  c("Pre-Internment Location Fixed Effects", 
                                                    "\\checkmark", "\\checkmark", "\\checkmark")),
          title = "Internment Status and Political Engagement")

